package com.dbq.fast.business.product.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.dbq.fast.App;
import com.dbq.fast.R;
import com.dbq.fast.analysis.EventConstant;
import com.dbq.fast.analysis.FireBaseUserPurchaseTrack;
import com.dbq.fast.analysis.YibaAnalysis;
import com.dbq.fast.business.login.LoginProgressActivity;
import com.dbq.fast.business.me.ShareActivity;
import com.dbq.fast.business.product.event.FaceBookUserPurchaseTrack;
import com.dbq.fast.business.product.ProductTypeActivity;
import com.dbq.fast.business.product.bean.ServiceType;
import com.dbq.fast.common.bean.User;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 */

public class ServiceCardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<ServiceType.AppServiceListBean> data;
    private Context context;
    //套餐类型

    public ServiceCardAdapter(Context context, List<ServiceType.AppServiceListBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == 0) {
            View rootView = LayoutInflater.from(context).inflate(R.layout.adapter_service_item_view, parent, false);
            return new ProductViewHolder(rootView);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder1, int position) {
        ServiceType.AppServiceListBean serviceBean = data.get(position);
        if (holder1 instanceof ProductViewHolder) {
            if (serviceBean.data != null) {

                ProductListAdapter adapter = new ProductListAdapter(serviceBean.data);
                //GridLayout 3列
                LinearLayoutManager llm = new LinearLayoutManager(((ProductViewHolder) holder1).recyclerView.getContext());

                ((ProductViewHolder) holder1).recyclerView.setLayoutManager(llm);
                ((ProductViewHolder) holder1).recyclerView.setAdapter(adapter);

                ((ProductViewHolder) holder1).recyclerView.setNestedScrollingEnabled(true);
            }
        }
    }

    @Override
    public int getItemViewType(int position) {
        return data.get(position).type;
    }

    @Override
    public int getItemCount() {
        if (data == null) return 0;
        return data.size();
    }

    static class ProductViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.recyclerView)
        RecyclerView recyclerView;


        public ProductViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
